package com.example.demo.mapper;

import com.example.demo.entity.AfshopComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会员评论表 Mapper 接口
 * </p>
 *
 * @author Mr.We
 * @since 2024-06-25
 */
@Mapper
public interface AfshopCommentMapper extends BaseMapper<AfshopComment> {
    @Select("select * from afshop_comment where id = #{value}")
    AfshopComment queryObject(@Param("value") Integer id);

    @Select("<script>" +
            "select distinct c.* from afshop_comment c" +
            "        <if test='hasPic != null and hasPic == 1'>" +
            "            left join afshop_comment_picture cp on cp.comment_id = c.id" +
            "        </if>" +
            "        where 1 = 1" +
            "        <if test='typeId != null and typeId != \"\"'>" +
            "            and c.type_id = #{typeId}" +
            "        </if>" +
            "        <if test='valueId != null and valueId != \"\"'>" +
            "            and c.value_id = #{valueId}" +
            "        </if>" +
            "        <if test='goodsId != null and goodsId != \"\"'>" +
            "            and c.value_id = #{goodsId}" +
            "        </if>" +
            "        <if test='userId != null and userId != \"\"'>" +
            "            and c.user_id = #{userId}" +
            "        </if>" +
            "        <if test='asPic != null and hasPic == 1'>" +
            "            and cp.id is not null" +
            "        </if>" +
            "        <choose>" +
            "            <when test='sidx != null and sidx.trim() != null' >" +
            "                order by ${sidx} ${order}" +
            "            </when>" +
            "            <otherwise>" +
            "                order by id desc" +
            "            </otherwise>" +
            "        </choose>" +
            "        <if test='offset != null and limit != null'>" +
            "            limit #{offset}, #{limit}" +
            "        </if>" +
            "</script>")
    List<AfshopComment> queryList(Map<String, Object> map);

    @Select("<script>" +
            "select count(c.id) from afshop_comment c" +
            "        where 1= 1" +
            "        <if test='typeId != null and typeId != \"\"'>" +
            "            and c.type_id = #{typeId}" +
            "        </if>" +
            "        <if test='valueId != null and valueId != \"\"'>" +
            "            and c.value_id = #{valueId}" +
            "        </if>" +
            "        <if test='goodsId != null and goodsId != \"\"'>" +
            "            and c.value_id = #{goodsId}" +
            "        </if>" +
            "</script>")
    int queryTotal(Map<String, Object> map);

    @Select("<script>" +
            "select count(distinct c.id) from afshop_comment c" +
            "        left join afshop_comment_picture cp on cp.comment_id = c.id" +
            "        where 1= 1 and cp.id > 0" +
            "        <if test='typeId != null and typeId != \"\"'>" +
            "            and c.type_id = #{typeId}" +
            "        </if>" +
            "        <if test='valueId != null and valueId != \"\"'>" +
            "            and c.value_id = #{valueId}" +
            "        </if>" +
            "</script>")
    int queryhasPicTotal(Map<String, Object> map);
}
